//package cn.com.kblog.util;
//
//
//import java.io.IOException;
//import java.net.URISyntaxException;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStreamWriter;
//import java.io.Writer;
//import java.net.URISyntaxException;
//import java.util.ArrayList;
//import java.util.List;
//
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
//
//import com.baidu.inf.iis.bcs.BaiduBCS;
//import com.baidu.inf.iis.bcs.auth.BCSCredentials;
//import com.baidu.inf.iis.bcs.auth.BCSSignCondition;
//import com.baidu.inf.iis.bcs.http.HttpMethodName;
//import com.baidu.inf.iis.bcs.model.BCSClientException;
//import com.baidu.inf.iis.bcs.model.BCSServiceException;
//import com.baidu.inf.iis.bcs.model.BucketSummary;
//import com.baidu.inf.iis.bcs.model.Empty;
//import com.baidu.inf.iis.bcs.model.ObjectListing;
//import com.baidu.inf.iis.bcs.model.ObjectMetadata;
//import com.baidu.inf.iis.bcs.model.ObjectSummary;
//import com.baidu.inf.iis.bcs.model.Resource;
//import com.baidu.inf.iis.bcs.model.SuperfileSubObject;
//import com.baidu.inf.iis.bcs.model.X_BS_ACL;
//import com.baidu.inf.iis.bcs.policy.Policy;
//import com.baidu.inf.iis.bcs.policy.PolicyAction;
//import com.baidu.inf.iis.bcs.policy.PolicyEffect;
//import com.baidu.inf.iis.bcs.policy.Statement;
//import com.baidu.inf.iis.bcs.request.CreateBucketRequest;
//import com.baidu.inf.iis.bcs.request.GenerateUrlRequest;
//import com.baidu.inf.iis.bcs.request.GetObjectRequest;
//import com.baidu.inf.iis.bcs.request.ListBucketRequest;
//import com.baidu.inf.iis.bcs.request.ListObjectRequest;
//import com.baidu.inf.iis.bcs.request.PutObjectRequest;
//import com.baidu.inf.iis.bcs.request.PutSuperfileRequest;
//import com.baidu.inf.iis.bcs.response.BaiduBCSResponse;
//
///**
// * 上传文件4BAE
// * @author KK.Luo
// * Email luokai8@vip.qq.com
// * @date 2013-12-4下午12:54:54
// */
//@SuppressWarnings("unused")
//public class UploadUtils4BCS {
//	private static final Log log = LogFactory.getLog(UploadUtils4BCS.class);
//	// ----------------------------------------
//	static String host = "bcs.duapp.com";
//	static String accessKey = AppConfigUtil.get("bae.username");
//	static String secretKey =  AppConfigUtil.get("bae.password");
//	static String bucket = AppConfigUtil.get("bae.bucket");;
//	// ----------------------------------------
//	private static BaiduBCS baiduBCS;
//	
//	static{
//		BCSCredentials credentials = new BCSCredentials(accessKey, secretKey);
//		baiduBCS = new BaiduBCS(credentials, host);
//		baiduBCS.setDefaultEncoding("UTF-8"); // Default UTF-8
//	}
//	
//
//	
//	/**
//	 * 返回
//	 * @param file 
//	 * @return 上传成功后的图片URL
//	 */
//	public static String uploadImage(File file) {
//		String filename = _createFilename(file);
//		try {
//			PutObjectRequest request = new PutObjectRequest(bucket, "/images/"+filename, file);
//			ObjectMetadata metadata = new ObjectMetadata();
//			request.setMetadata(metadata);
//			// 设置成公开读
//	        request.setAcl(X_BS_ACL.PublicRead);
//			BaiduBCSResponse<ObjectMetadata> response = baiduBCS.putObject(request);
//			ObjectMetadata objectMetadata = response.getResult();
//			log.info("x-bs-request-id: " + response.getRequestId());
//			log.info(objectMetadata);
//			String url = "http://"+host+"/"+bucket+"/images/"+filename;
//			return url;
//		}catch (Exception e) {
//			 e.printStackTrace();
//	         log.error(e.getMessage());
//	         return null;
//		}
//		
//	}
//	
//
//	
//	/**
//	 * 生成文件唯一文件名
//	 * @param file
//	 * @return
//	 */
//	private static String _createFilename(File file) {
//		String oldName = file.getName();
//		String fileType = oldName.substring(oldName.lastIndexOf("."), oldName.length());
//		String newName = System.currentTimeMillis() + fileType;
//		return newName;
//	}
//}